package com.appspot.zarm.game;

import java.util.HashMap;
import java.util.Map;

public class BoardStorage {

	private Map<PlayerPair, Board> boards = new HashMap<PlayerPair, Board>();
	
	public Board getBoard(Player player) {
		PlayerPair pair = getPlayerPair(player);
		return boards.get(pair);
	}
	
	public void putBoard(Player player1, Player player2, Board board) {
		boards.put(new PlayerPair(player1, player2), board);
	}

	public void removeBoard(Player player) {
		PlayerPair pair = getPlayerPair(player);
		boards.remove(pair);
	}
	
	private PlayerPair getPlayerPair(Player player) {
		for (PlayerPair pair : boards.keySet()) {
			if (player.equals(pair.getPlayer1()) || player.equals(pair.getPlayer2())) return pair;
		}
		return null;
	}
}
